<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Exposure_orderModel
 * 诚信认证的模型
 * @author wml
 */

namespace Home\Model;

use Think\Model;

class CompanyCertificatModel extends Model {
    /* 自动验证规则 */

    protected $_validate = array(
        array('company_name', "require", '请输入公司名称', self::MUST_VALIDATE, 'regex'),
        array('company_url', "require", '请输入公司网址', self::MUST_VALIDATE, 'regex'),
        array('regist_num', "require", '请输入注册号', self::MUST_VALIDATE, 'regex'),
        array('regist_address', "require", '请输入注册地址', self::MUST_VALIDATE, 'regex'),
        array('legal_person', "require", '请输入公司法人', self::MUST_VALIDATE, 'regex'),
        array('build_time', "require", '请输入注册时间', self::MUST_VALIDATE, 'regex'),
        //  array('build_time', "2012-1-15,", '请输入正确的注册时间', self::MUST_VALIDATE, 'between'),
        array('Landline', "require", '请输入电话座机', self::MUST_VALIDATE, 'regex'),
       //    array('business_img', "require", '必须上传营业执照', self::MUST_VALIDATE, 'regex'),
        //    array('id_is_img', "require", '必须上传身份证正面图', self::MUST_VALIDATE, 'regex'),
       //     array('id_the_img', "require", '必须上传身份证发面图', self::MUST_VALIDATE, 'regex'),
       //     array('id_hold', "require", '必须上传手持身份证图', self::MUST_VALIDATE, 'regex'),
        array('business_area', "require", '请输入经营范围', self::MUST_VALIDATE, 'regex'),
        array('business_area', '0,140', '文案不能超过140个字符', self::MUST_VALIDATE, 'length', self::MODEL_BOTH),
    );

    public function editData($data) {

        $data["user_id"] = session("user.id");
        $data["add_time"] = date("Y-m-d H:i:s");
        if (!$this->create($data)) {
            $this->error = $this->getError();
            return false;
        }
        /* 添加或新增行为 */
        if (empty($data['id'])) { //新增数据
            $id = $this->add(); //添加行为
            if (!$id) {
                $this->error = "添加失败，请重试";
                return false;
            }
        } else { //更新数据
            $status = $this->save(); //更新基础内容
            if (false === $status) {
                $this->error = "修改失败，请重试";
                return false;
            }
        }
        return $data;
    }

    public function deleteData($map) {
        $result = $this->where($map)->delete();
        return $result;
    }
    
    /*
     * 上传
     */

    public function uploadCertificates($data) {

        $info = uploadPhotos($_FILES, 'businessLicense');
     
        $info1 =   explode(',',$info['mess']);
        
        $data['business_img'] = $info1[0];   //营业执照
        
        $data['id_is_img'] = $info1[1]; //身份证正面
     
        $data['id_the_img'] =  $info1[2]; //身份证反面
       
        $data['id_hold']  =  $info1[3]; //手持身份证
       $this->create($data);
       
        $status = $this->where('user_id='.session('user.id'))->save(); //更新基础内容
        if (!$status) {
            return false;
        }
        return $data;
    }
 
    /*
     * 根据ID查询详细信息
     *  @author  csb
     */

    public function getDataById($map, $field = "*") {
        $relust = $this->field($field)->where($map)->find();
        return $relust;
    }

    /*
     * 获取云曝光的列表
     * @author  csb
     */
    public function getExposureOrder($map = "1=1", $field = "*", $limit = false) {
        $datalist = getPages($this, $map, null, C('PAGESIZE'), null, $field);
        return $datalist;
    }

}

?>
